package oop.data;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import oop.db.dao.SectionStructureDAO;
import oop.db.dao.TopicDAO;
import oop.db.dao.UserDAO;

public class TestStructure {

	private long id;
	private String name;
	private String description;
	private long authorId;
	private long topicId;
	private Date createDate;
	private List<SectionStructure> sectionStructures = null;

	public TestStructure(long id, String name, String description, long authorId, 
			long topicId, Date createDate) {
		this.id = id;
		this.name = name;
		this.description = description;
		this.authorId = authorId;
		this.topicId = topicId;
		this.createDate = createDate;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public long getId() {
		return id;
	}

	public List<SectionStructure> getSectionStructures() throws SQLException {
		if (sectionStructures == null) {
			sectionStructures = SectionStructureDAO.fetchByTestStructure(id);
		}
		return sectionStructures;
	}
	
	public void addSectionStructure(SectionStructure structure) throws SQLException {
		getSectionStructures().add(structure);
	}
	
	public void removeSectionStructure(SectionStructure structure) throws SQLException {
		getSectionStructures().remove(structure);
	}

	public void setTopic(Topic topic) {
		this.topicId = topic.getId();
	}

	public Topic getTopic() throws SQLException {
		return TopicDAO.fetchById(topicId);
	}
	
	public User getAuthor() throws SQLException {
		return UserDAO.fetchById(authorId).get(0);
	}
	
	public Date getCreateDate() {
		return createDate;
	}
	
}
